package com.liuheng.manager.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.liuheng.manager.service.CategoryBrandService;
import com.liuheng.spzx.model.dto.product.CategoryBrandDto;
import com.liuheng.spzx.model.entity.product.Brand;
import com.liuheng.spzx.model.entity.product.CategoryBrand;
import com.liuheng.spzx.model.vo.common.Result;
import com.liuheng.spzx.model.vo.common.ResultCodeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {
    @Autowired
    private CategoryBrandService categoryBrandService;
    @GetMapping("/{page}/{limit}")
    public Result<Page<CategoryBrand>> findCategoryBrand(@PathVariable int page, @PathVariable int limit, CategoryBrandDto categoryBrandDto){
        Page<CategoryBrand> pageInfo=categoryBrandService.findByPage(page,limit,categoryBrandDto);
        return Result.build(pageInfo,ResultCodeEnum.SUCCESS);
    }
    @PostMapping("/save")
    public Result saveCategoryBrand(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.save(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @PutMapping("/updateById")
    public Result updateCategoryBrand(@RequestBody CategoryBrand categoryBrand){
        categoryBrandService.updateById(categoryBrand);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    @DeleteMapping("/delete/{id}")
    public Result deleteCategoryBrandById(@PathVariable Long id){
        categoryBrandService.removeById(id);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    //根据分类id查询品牌名称
    @GetMapping("/findBrandByCategoryId/{categoryId}")
    public Result findBrandByCategoryId(@PathVariable Long categoryId){
        List<Brand> list=categoryBrandService.findBrandByCategoryId(categoryId);
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }
}
